package models

import "time"

type User struct {
	ID               uint      `json:"id" gorm:"primaryKey;autoIncrement"`
	Email            string    `json:"email" gorm:"type:varchar(255);unique;not null"`
	PasswordHash     string    `json:"password_hash" gorm:"type:varchar(255)"`
	VerificationCode string    `json:"verification_code,omitempty" gorm:"type:varchar(255)"`
	Name             string    `json:"name" gorm:"type:varchar(255)"`
	CreatedAt        time.Time `json:"created_at" gorm:"autoCreateTime"`
	UpdatedAt        time.Time `json:"updated_at" gorm:"autoUpdateTime"`

	// 关联关系
	UserIntentions []UserIntention `json:"user_intentions,omitempty" gorm:"foreignKey:UserID"`
	Dataflows      []Dataflow      `json:"dataflows,omitempty" gorm:"foreignKey:UserID"`
}

type UserIntention struct {
	ID        uint      `json:"id" gorm:"primaryKey;autoIncrement"`
	UserID    uint      `json:"user_id" gorm:"not null;index"`
	Intention string    `json:"intention" gorm:"type:varchar(255);not null"`
	Request   string    `json:"request" gorm:"type:text;not null"`
	CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
	UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`

	// 关联关系
	User      User       `json:"-" gorm:"foreignKey:UserID"` // 避免循环引用
	Dataflows []Dataflow `json:"dataflows,omitempty" gorm:"foreignKey:IntentionID"`
}

type Dataflow struct {
	ID          uint      `json:"id" gorm:"primaryKey;autoIncrement"`
	UserID      uint      `json:"user_id" gorm:"not null;index"`
	IntentionID uint      `json:"intention_id" gorm:"not null;index"`
	Dataflow    string    `json:"dataflow" gorm:"type:text;not null"`
	CreatedAt   time.Time `json:"created_at" gorm:"autoCreateTime"`
	UpdatedAt   time.Time `json:"updated_at" gorm:"autoUpdateTime"`

	// 关联关系
	UserIntention UserIntention `json:"-" gorm:"foreignKey:IntentionID"`
	User          User          `json:"-" gorm:"foreignKey:UserID"`
}
